package com.cloudkinto.controller.covershows;


import com.cloudkinto.service.covershows.vo.AdviceReq;
import com.cloudkinto.service.covershows.vo.NewsInformationAddReq;
import com.cloudkinto.service.covershows.vo.NewsInformationUpdateReq;
import io.swagger.annotations.ApiImplicitParams;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.cloudkinto.service.covershows.NewsInformationService;

import com.cloudkinto.common.web.PageResult;
import com.cloudkinto.common.web.SingleResult;

import javax.servlet.http.HttpServletRequest;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;

import java.util.HashMap;
import java.util.Map;

import com.cloudkinto.base.BaseController;

/**
 * <p>
 *  前端控制器
 * </p>
 * @author zhangyy
 * @since 2020-09-27
 */
@RestController
@Api(tags = "新闻专题模块")
@RequestMapping("/api/coverShows")
public class NewsInformationController extends BaseController {
    private final Logger logger = LoggerFactory.getLogger(NewsInformationController.class);

    @Autowired
    private NewsInformationService service;

//    @PostMapping("")
//    @ApiOperation(value = "新增", notes = "新增")
//    public SingleResult add(@RequestBody @Validated NewsInformationAddReq req) {
//        Long userId = getCurrentUserId();
//        service.add(req,userId);
//        return SingleResult.success("新增成功",null);
//    }
//
//    @GetMapping("/updateInit/{id}")
//    @ApiOperation(value = "编辑初始化", notes = "编辑初始化")
//    public SingleResult updateInit(@PathVariable("id") Long id) {
//        return service.updateInit(id);
//    }
//
//    @PutMapping("")
//    @ApiOperation(value = "修改", notes = "修改")
//    public SingleResult update(@RequestBody @Validated NewsInformationUpdateReq req) {
//        Long userId = getCurrentUserId();
//        service.update(req,userId);
//        return SingleResult.success("修改成功",null);
//    }
//
//    @DeleteMapping("/{id}")
//    @ApiOperation(value = "根据id删除", notes = "根据id删除")
//    public SingleResult delete(@PathVariable("id") Long id) {
//        Long userId = getCurrentUserId();
//        return SingleResult.success("删除成功",service.delete(id,userId));
//    }

    @GetMapping("/{id}")
    @ApiOperation(value = "根据id查看详情", notes = "根据id查看详情")
    public SingleResult detail(@PathVariable("id") Long id) {
        return SingleResult.success("查询成功",service.detail(id));
    }


    @GetMapping("/listPage")
    @ApiOperation(value = "查询（分页）", notes = "查询（分页）")
    @ApiImplicitParams({@ApiImplicitParam(name = "current", value = "当前页"),
            @ApiImplicitParam(name = "pageSize", value = "页面大小")})
    public PageResult listPage(HttpServletRequest request){

        Map<String, String> map = new HashMap<>();
        String current = request.getParameter("current");
        String size = request.getParameter("pageSize");
        map.put("current", current);
        map.put("pageSize", size);
        return service.getListPage(map);
    }

    @GetMapping("dataStatistics")
    @ApiOperation(value = "数据统计", notes = "数据统计")
    public SingleResult dataStatistics() {
        return service.dataStatistics();
    }

//    @GetMapping("storageList")
//    @ApiOperation(value = "获取仓库列表", notes = "数据统计")
//    public SingleResult storageList() {
//        return service.storageList();
//    }
//
//    @GetMapping("jpRegionList")
//    @ApiOperation(value = "获取地区列表", notes = "数据统计")
//    public SingleResult jpRegionList() {
//        return service.jpRegionList();
//    }
    @PostMapping("advice")
    @ApiOperation(value = "意见反馈", notes = "意见反馈")
    public SingleResult advice(@RequestBody @Validated AdviceReq req){
        service.advice(req);
        return SingleResult.success();
    }

}

